Whether a graph is directed or undirected ,the adjacency -list representation requires O(V+E) memory.To represent a WEIGHTED GRAPH each edge has a weight associated with it ,the weight of the edge (u,v) in E is simply stored with vertex v in u's adjacency - list.The major drawback of this representation is that there is no quick way of finding a given edge.
For the ADJACENCY MATRIX representation of a graph G=(V,E),we assume that the vaertices are numbered in some arbitary manner.The adjacency matrix representation of a graph G then consists of a |V| by |V| matrix such that
aij = | 1 if(i,j) belong to E,
| 0 if (i,j) does not belong to E
Adjacency matrix reprentation of directed and undirected graphs are shown
below,the adjacency matrix of a graph requires memory of the order V square,
independent of the number of edges.To represent the weighted graphs we
add weight w(u,v) of the edge E(u,v) as the entry in row u and column v
of the adjacency matrix.if the edge doesnot exists ,a NIL value can be
stored as its corresponding entry
Representation of a graph
Data Structure Required to
strore the graph
We require two Objects for the adjacency
representation of Graphs ,one for representing the Vertices and other for
representing the Edges ,the fundamental field present in the two are as
follows.
Keys to Home
Graph Algorithms
The Tutorial was written by Abhishek Goyal,Marghoob Mohiyuddin,Pooja Nath and Ruchi Saran |
Please email comments to:
[email protected] [email protected] |